package com.example.demo.common;

import lombok.Data;

import java.io.Serializable;

/*
统一结果封装，大部分接口返回的结果
 */


@Data
public class Result implements Serializable {
    private int code;
    private String msg;
    private Object data;
    public static Result succ(Object data) {
        return succ(1,"成功",data);
    }
    public static Result succ(String msg, Object data) {
        return succ(1,msg,data);
    }
    public static Result succ(int code,String msg, Object data) {
        Result m = new Result();
        m.setCode(code);
        m.setData(data);
        m.setMsg(msg);
        return m;
    }

    public static Result fail(String msg) {
        return fail(0,msg,null);
    }
    public static Result fail(String msg, Object data) {
        return fail(0,msg,data);
    }
    public static Result fail(int code,String msg, Object data) {
        Result m = new Result();
        m.setCode(code);
        m.setData(data);
        m.setMsg(msg);
        return m;
    }
}
